/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import beans.DBMS;
import beans.Custemer;
import java.sql.ResultSet;

/**
 *
 * @author Yash
 */
public class CustemerDao {
   private static DBMS d=new DBMS();
    public static boolean verify(Custemer c){
        boolean flag=false;
        String sql="select * from custemers where email='"+c.getCemail()+"' AND password='"+c.getCpassword()+"'";
        ResultSet rs=d.gselect(sql);
        try{
            if(rs.next()){
                flag=true;
            }
        }
        catch(Exception e){
            e.printStackTrace();
        }
        return flag;
    }
    
    public static boolean addCustemer(Custemer c){
        boolean flag=false;
        String sql="insert into custemers(fname,lname,email,password) values('"+c.getCfname()+"','"+c.getClname()+"','"+c.getCemail()+"','"+c.getCpassword()+"')";
        if(d.guid(sql)==1){
            flag=true;
        } 
        return flag;
    }
    public static String getPassword(String cemail){
        String password="";
        String sql="select password from custemers where email='"+cemail+"'";
        ResultSet rs=d.gselect(sql);
        try{
            if(rs.next()){
                password=rs.getString("password");
            }
        }
        catch(Exception e){
            e.printStackTrace();
        }
        return password;
    }

    public static void fillUser(Custemer c) {
        ResultSet rs=null;
        String sql="select * from custemers where email='"+c.getCemail()+"'";
        rs=d.gselect(sql);
        try{
            while(rs.next())
            { 
              //c.getCemail();
              // c.setCfname(rs.getString("fname"));
              // c.setClname(rs.getString("lname"));
               //c.setCemail(rs.getString("email"));
               c.setCpassword(rs.getString("password"));
            }
        }catch(Exception e)
        {
            e.printStackTrace();
        }
    }
    
}
